import net.coobird.thumbnailator.Thumbnails;
import net.coobird.thumbnailator.geometry.Positions;
import org.junit.Test;

import javax.imageio.ImageIO;
import java.io.File;
import java.io.IOException;

/**
 * @author lvhuiyuan
 * @date 2020/12/14 3:22 下午
 */
public class PictureTest {

    public String imgParent = "src/main/resources/images/";

    /**
     * 原图片尺寸不变，质量压缩
     */
    @Test
    public void originWidth() throws IOException {
        Thumbnails.of(imgParent+"flower.jpg").scale(1).outputQuality(0.1).toFile(imgParent + "test1.jpg");
    }

    /**
     * 生成指定大小的图片
     */
    @Test
    public void test2() throws IOException {
        Thumbnails.of(imgParent+"flower.jpg").size(300,300).toFile(imgParent + "test2.jpg");
    }

    /**
     *原图按比例缩小
     */
    @Test
    public void test3() throws IOException {
        Thumbnails.of(imgParent+"flower.jpg").scale(0.5).toFile(imgParent + "test3.jpg");
    }

    /**
     *原图旋转180度
     */
    @Test
    public void test4() throws IOException {
        Thumbnails.of(imgParent+"flower.jpg").scale(0.5).rotate(180).toFile(imgParent + "test4.jpg");
    }

    /**
     *原图更换后缀
     */
    @Test
    public void test5() throws IOException {
        Thumbnails.of(imgParent+"flower.jpg").scale(0.5).outputFormat("png").toFile(imgParent + "test5.png");
    }

    /**
     *截取原图中心600*600的一半
     */
    @Test
    public void test6() throws IOException {
        Thumbnails.of(imgParent+"flower.jpg").scale(0.5).sourceRegion(Positions.CENTER,600,600).toFile(imgParent + "test6.jpg");
    }

    /**
     *原图中心加透明度水印图片
     */
    @Test
    public void test7() throws IOException {
        Thumbnails.of(imgParent+"flower.jpg").scale(0.5).watermark(Positions.CENTER,ImageIO.read(new File(imgParent+"water.jpg")),0.25f).toFile(imgParent + "test7.png");
    }


}
